package com.example.medicine;

import com.example.medicine.Bean.yian.yian_chufang;
import com.example.medicine.Bean.yian.yian_jibing;
import com.example.medicine.Bean.yian.yian_xiyi;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

public class yianSelectProvider {
    public String yianSelect(yian_chufang yian_chufang,yian_xiyi yian_xiyi,yian_jibing yian_jibing) {
        String zy=yian_chufang.getZhongyaoming();
        String xy=yian_xiyi.getName();
        String jb=yian_jibing .getMingcheng();
        System.out.println("jb"+jb);
        System.out.println(jb==null);
        System.out.println(jb.equals(null));
        System.out.println(jb=="null");
        System.out.println(jb.equals("null"));//这个判断空
        System.out.println(jb.equals(""));
        System.out.println(jb.isEmpty());
        return new SQL(){
            {
                SELECT("DISTINCT a.*");
                FROM("yian a");
                LEFT_OUTER_JOIN("yian_chufang b ON a.id = b.yianid");
                LEFT_OUTER_JOIN("yian_xiyi c ON a.id = c.yianid");
                LEFT_OUTER_JOIN("yian_jibing d ON a.id = d.yianid");
                if(!zy.equals("null")&&zy!=null&&zy!="") {

                    WHERE("zhongyaoming like concat('%',#{yian_chufang.zhongyaoming},'%')");
                }
//
                if(!xy.equals("null")&&xy!= null&&xy!= "null"&&xy!=""&&!xy.equals("[]")) {
                    WHERE("name like  concat('%',#{yian_xiyi.name},'%')");
//                    WHERE("1=1");
                }
                if(!jb.equals("null")&&jb!= null&&jb!= "null"&&jb!= "") {
                    WHERE("mingcheng like  concat('%',#{yian_jibing.mingcheng},'%')");
//                    WHERE("1=1");
                }
                WHERE("a.fenlei='中医'");
            }
        }.toString();
    }
    public String mzhenSelect(yian_chufang yian_chufang,yian_xiyi yian_xiyi,yian_jibing yian_jibing) {
        String zy=yian_chufang.getZhongyaoming();
        String xy=yian_xiyi.getName();
        String jb=yian_jibing .getMingcheng();
        return new SQL(){
            {
                SELECT("DISTINCT a.*");
                FROM("yian a");
                LEFT_OUTER_JOIN("yian_chufang b ON a.id = b.yianid");
                LEFT_OUTER_JOIN("yian_xiyi c ON a.id = c.yianid");
                LEFT_OUTER_JOIN("yian_jibing d ON a.id = d.yianid");
                if(!zy.equals("null")&&zy!=null&&zy!="") {

                    WHERE("zhongyaoming like concat('%',#{yian_chufang.zhongyaoming},'%')");
                }
//
                if(!xy.equals("null")&&xy!= null&&xy!= "null"&&xy!=""&&!xy.equals("[]")) {
                    WHERE("name like  concat('%',#{yian_xiyi.name},'%')");
//                    WHERE("1=1");
                }
                if(!jb.equals("null")&&jb!= null&&jb!= "null"&&jb!= "") {
                    WHERE("mingcheng like  concat('%',#{yian_jibing.mingcheng},'%')");
//                    WHERE("1=1");
                }
                WHERE("a.fenlei='西医'");
            }
        }.toString();
    }

}
